home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-06 | 13.7 KB | 461 lines | [TEXT/KAHL] |
- // -----------------------------------------------------------------------------
- // File : demoWind.c
- // Date : October 14, 1994
- // Author : Jim Stout
- // Purpose : routines used for the demoCDEF Window
- //
- // -----------------------------------------------------------------------------
- #include "demoWind.h"
-
- #include "jimsCDEF.h"
- #include "dialogAssist.h"
-
- extern SysEnvRec gSysEnv;
- extern short gDemoType;
- extern ControlHandle gPopCtl, gBoxCtl;
- extern ControlHandle gProgBar1, gProgBar2, gProgBar3;
-
- MenuHandle dynMenu;
-
- //=============================================================================
- // create new controls - called from doNewWindow() in demoShell.c
- //=============================================================================
- void doNewControls(WindowPtr theWindow)
- {
- Rect r;
- short ht;
-
- if(dynMenu) {
- DeleteMenu(512);
- DisposeMenu(dynMenu);
- }
- dynMenu = 0;
-
- //-----------------------------------------------------------------------------
- // create the popup menu control
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 10, 6, 220, 25);
-
- gPopCtl = NewControl(theWindow, &r, "\pShow:", true,
- popupTitleRightJust, // right justified
- 132, // menu id
- popupInsetFrame+45, // ext varCode + title width
- 16*popUp+ctl3D, 0L);
-
- //-----------------------------------------------------------------------------
- // create the group box, inset 10 pixels from edge of window.
- //-----------------------------------------------------------------------------
-
- r = theWindow->portRect;
- InsetRect(&r, 10, 10);
- r.top+=14; // leave room for popup above
-
- ht = r.bottom-r.top; // calculate true size of box
- r.bottom = r.top+16; // but this is the control rect
-
- gBoxCtl = NewControl(theWindow, &r, "\p", true,
- 0, // control value
- 0, // minimum value
- ht, // true height of control
- 16*groupBox+insetBox, 0L);
- }
-
- //=============================================================================
- // Get rid of controls in current window and create new ones
- //=============================================================================
-
- void doSwapControls(WindowPtr theWindow)
- {
- short newVal;
- ControlHandle thisCtl, nextCtl;
-
- newVal = GetCtlValue(gPopCtl); // popUp menu setting
-
- if(newVal != gDemoType) { // if it changed,
-
- //-----------------------------------------------------------------------------
- // delete the existing controls (not the popup & groupbox)
- //-----------------------------------------------------------------------------
-
- thisCtl = nextCtl = ((WindowPeek)theWindow)->controlList;
- while(thisCtl) {
- nextCtl = (**thisCtl).nextControl;
- if(thisCtl != gPopCtl && thisCtl != gBoxCtl)
- DisposeControl(thisCtl);
- thisCtl = nextCtl;
- }
- if(dynMenu) {
- DeleteMenu(512);
- DisposeMenu(dynMenu);
- dynMenu = 0;
- }
-
- ValidRect(&theWindow->portRect); // no flicker needed as
- gDemoType = newVal; // new controls draw
-
- //-----------------------------------------------------------------------------
- // create some new controls
- //-----------------------------------------------------------------------------
-
- switch(gDemoType) {
- case 1:
- make3DControls(theWindow);
- break;
- case 2:
- makePopupControls(theWindow);
- break;
- case 3:
- makeArrowControls(theWindow);
- break;
- case 4:
- makeDateControls(theWindow);
- break;
- case 5:
- makeSliderControls(theWindow);
- break;
- case 6:
- makeProgressControls(theWindow);
- break;
- }
- }
- }
-
- //=============================================================================
- // Handle a mouse click in a control
- //=============================================================================
- void doControlClick(ControlHandle theCtl, short thePart)
- {
- switch(gDemoType) {
- case 1:
- SetCtlValue(theCtl, !GetCtlValue(theCtl));
- break;
- }
- }
-
- //=============================================================================
- // Move the progress bar controls
- //=============================================================================
- void doProgress()
- {
- short val, max, min;
-
- // bump the value of the progress bars
-
- val = GetCtlValue(gProgBar1);
- max = GetCtlMax(gProgBar1);
- min = GetCtlMin(gProgBar1);
-
- if(val < max)
- SetCtlValue(gProgBar1, ++val);
- else
- SetCtlValue(gProgBar1, min);
-
- // make the "barber poles" rotate
-
- SetCtlValue(gProgBar2, !GetCtlValue(gProgBar2));
- SetCtlValue(gProgBar3, !GetCtlValue(gProgBar3));
- }
-
- //=============================================================================
- // create a couple of 3D control samples
- //=============================================================================
- void make3DControls(WindowPtr theWindow)
- {
- ControlHandle hCtl;
- Rect r;
- Str255 s,numStr;
- short inx;
- long num;
-
- //-----------------------------------------------------------------------------
- // create a couple of check boxes
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 30, 73, 130, 89);
-
- for(inx=1;inx<3;inx++) {
- GetIndString(s, 129, 3);
- num = inx;
- NumToString(num, numStr);
- pStrCat((char *)s, (char *)numStr);
- hCtl = NewControl(theWindow, &r, s, true,
- 0, // control value
- 0, // minimum value
- 1, // maximum value
- 16*button3D+checkBoxProc, 0L);
- OffsetRect(&r, 0, 26);
- }
-
- //-----------------------------------------------------------------------------
- // create a couple of radio buttons
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 150, 73, 250, 89);
-
- for(inx=1;inx<3;inx++) {
- GetIndString(s, 129, 2);
- num = inx;
- NumToString(num, numStr);
- pStrCat((char *)s, (char *)numStr);
- hCtl = NewControl(theWindow, &r, s, true,
- 0, // control value
- 0, // minimum value
- 1, // maximum value
- 16*button3D+radioButProc, 0L);
- OffsetRect(&r, 0, 26);
- }
-
- //-----------------------------------------------------------------------------
- // create a 2 line push button
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 280, 73, 340, 113);
-
- hCtl = NewControl(theWindow, &r, "\pPush\rButton", true,
- 0, // control value
- 0, // minimum value
- 1, // maximum value
- 16*button3D+pushButProc, 0L);
- }
-
- //=============================================================================
- // create some popup controls
- //=============================================================================
- void makePopupControls(WindowPtr theWindow)
- {
- ControlHandle theCtl;
- Rect r;
-
- //-----------------------------------------------------------------------------
- // create a popup controll for the large icon menu
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 20, 40, 280, 94);
-
- theCtl = NewControl(theWindow, &r, "\pIcons:", true,
- popupTitleRightJust, // right justified
- 133, // menu id
- 70, // title width
- 16*popUp+ctl3D, 0L);
-
- //-----------------------------------------------------------------------------
- // create a menu dynamically and a popup control for it.
- //-----------------------------------------------------------------------------
-
- dynMenu = NewMenu(512, "\pDynamic");
- if(dynMenu) {
- AppendMenu(dynMenu, "\pThis menu was");
- AppendMenu(dynMenu, "\pcreated dynamically,");
- AppendMenu(dynMenu, "\pnot read from a ");
- AppendMenu(dynMenu, "\presource.");
- InsertMenu(dynMenu, -1);
-
- SetRect(&r, 20, 104, 280, 123);
-
- theCtl = NewControl(theWindow, &r, "\pDynamic:", true,
- popupTitleRightJust, // right justified
- 512, // menu id
- 70, // title width
- 16*popUp, 0L);
- }
-
- //-----------------------------------------------------------------------------
- // create a menu with colored & styled text items
- //-----------------------------------------------------------------------------
- OffsetRect(&r, 0, 29);
- theCtl = NewControl(theWindow, &r, "\pColored:", true,
- popupTitleRightJust, // right justified
- 134, // menu id
- 70, // title width
- 16*popUp, 0L);
-
- //-----------------------------------------------------------------------------
- // create a "type in" style menu - draws symbol only
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 290, 40, 314, 94);
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- popupTitleRightJust, // right justified
- 303, // menu id
- popupSymbolOnly, // title width
- 16*popUp, 0L);
-
- //-----------------------------------------------------------------------------
- // create a "icon only" style menu - draws icons only
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 290, 94, 330, 134);
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- popupTitleRightJust, // right justified
- 304, // menu id
- popupIconOnly, // title width
- 16*popUp+popupFixedWidth, 0L);
-
- //-----------------------------------------------------------------------------
- // create a "popupCenterText" style menu - draws item text centered in ctl rect
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 325, 40, 344, 94);
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- popupTitleRightJust, // right justified
- 302, // menu id
- popupCenterText, // title width
- 16*popUp+useWFont, 0L);
- }
-
- //=============================================================================
- // create a small arrow control and a large 3D arrow control - both vertical
- // and horizontal variations.
- //=============================================================================
- void makeArrowControls(WindowPtr theWindow)
- {
- ControlHandle theCtl;
- Rect r;
-
- SetRect(&r, 60, 66, 177, 84);
-
- theCtl = NewControl(theWindow, &r, "\pNumber 1:", true,
- 0, // control value
- -100, // minimum value
- 100, // maximum value
- 16*spinner, 0L);
-
- SetRect(&r, 60, 94, 180, 119);
-
- theCtl = NewControl(theWindow, &r, "\pNumber 2:", true,
- 0, // control value
- -100, // minimum value
- 100, // maximum value
- 16*spinner+bigArrows+ctl3D,
- 0L);
-
- SetRect(&r, 200, 66, 325, 84);
-
- theCtl = NewControl(theWindow, &r, "\pNumber 3:", true,
- 0, // control value
- -100, // minimum value
- 100, // maximum value
- 16*spinner+horizArrows,
- 0L);
-
- SetRect(&r, 200, 94, 332, 119);
-
- theCtl = NewControl(theWindow, &r, "\pNumber 4:", true,
- 0, // control value
- -100, // minimum value
- 100, // maximum value
- 16*spinner+bigArrows+horizArrows,
- 0L);
- }
-
- //=============================================================================
- // create a default date control - has both date & time
- //=============================================================================
- void makeDateControls(WindowPtr theWindow)
- {
- ControlHandle theCtl;
- Rect r;
-
- SetRect(&r, 42, 55, 300, 73);
-
- theCtl = NewControl(theWindow, &r, "\pDate & Time:", true,
- 0, // ignored
- ctl3D, // 1 for 3D
- 0, // 1 for 24 hour time
- 16*dateTime, 0L);
-
- SetRect(&r, 90, 83, 300, 101);
-
- theCtl = NewControl(theWindow, &r, "\pDate:", true,
- 0, // ignored
- 0, // 1 for 3D
- 0, // 1 for 24 hour time
- 16*dateTime+dateOnly, 0L);
-
- SetRect(&r, 90, 111, 300, 129);
-
- theCtl = NewControl(theWindow, &r, "\pTime:", true,
- 0, // ignored
- 0, // 1 for 3D
- only24, // 1 for 24 hour time
- 16*dateTime+timeOnly, 0L);
- }
-
- //=============================================================================
- // create both vertical and horizontal 3D sliders
- //=============================================================================
- void makeSliderControls(WindowPtr theWindow)
- {
- ControlHandle theCtl;
- Rect r;
-
- SetRect(&r, 50, 43, 50+vWid, 43+7*vHt+21);
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- 0, // control value
- 0, // minimum set by CDEF to 0
- 0, // maximum set by CDEF to 12*ticks
- 16*vSlider+ctl3D,
- 0L); // 7 ticks - range is 2-20
-
- OffsetRect(&r, 52, 0);
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- 0, // control value
- 0, // minimum set by CDEF to 0
- 0, // maximum set by CDEF to 12*ticks
- 16*vSlider,
- 5L); // 5 ticks - range is 2-20
-
- SetRect(&r, 183, 63, 183+hWid, 63+hHt);
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- 0, // control value
- 0, // minimum set by CDEF to 0
- 0, // maximum set by CDEF to 100
- 16*hSlider+ctl3D, 0L);
-
- OffsetRect(&r, 0, hHt+10);
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- 0, // control value
- 0, // minimum set by CDEF to 0
- 0, // maximum set by CDEF to 100
- 16*hSlider, 0L);
- }
-
- //=============================================================================
- // create a "normal" and "barber pole" progress bar (both horizontal)
- //=============================================================================
- void makeProgressControls(WindowPtr theWindow)
- {
- Rect r;
-
- SetRect(&r, 40, 68, 280, 80);
-
- gProgBar1 = NewControl(theWindow, &r, "\p", true,
- 10, // control value
- 0, // minimum value
- 240, // maximum value
- 16*progBar, 0L);
-
- OffsetRect(&r, 0, 40);
-
- gProgBar2 = NewControl(theWindow, &r, "\p", true,
- 1, // control value
- 0, // minimum value
- 1, // maximum value
- 16*progBar+barberPole, 0L);
-
- SetRect(&r, 315, 47, 331, 145);
-
- gProgBar3 = NewControl(theWindow, &r, "\p", true,
- 1, // control value
- 0, // minimum value
- 1, // maximum value
- 16*progBar+vertBar+roundBar+barberPole, 0L);
- }